package cn.leon.mysocket;

import android.app.Application;

import com.dhh.websocket.Config;
import com.dhh.websocket.RxWebSocket;
import com.dhh.websocket.SSLHelper;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * Created by leon on 2019/8/12.
 */
public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        initSocket();
    }

    private void initSocket() {
        OkHttpClient httpClient = new OkHttpClient.Builder()
                //ping/pong 设置：在设置config的时候，从okhttpclient中配置：（将此client设置到上面的config中）
                .pingInterval(60L, TimeUnit.SECONDS)
                .build();
        Config config = new Config.Builder()
                .setShowLog(true)
                .setClient(httpClient)   //if you want to set your okhttpClient
                .setShowLog(true, "xxx")
                .setReconnectInterval(10, TimeUnit.SECONDS)  //set reconnect interval
                .setSSLSocketFactory(SSLClient.getSSLSocketFactory(), SSLClient.getTrustManager()) // wss support
                .build();
        RxWebSocket.setConfig(config);
    }
}
